package com.ruoyi.sea.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sea.domain.SeaDevice;
import com.ruoyi.sea.service.ISeaDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备Controller
 * 
 * @author
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/sea/device")
public class SeaDeviceController extends BaseController
{
    @Autowired
    private ISeaDeviceService seaDeviceService;

    /**
     * 查询设备列表
     */
    @GetMapping("/list")
    public AjaxResult list(SeaDevice seaDevice)
    {
        return AjaxResult.success(seaDeviceService.selectSeaDeviceList(seaDevice));
    }


    /**
     * 查询海洋设备列表
     */
    @GetMapping("/listManage")
    public TableDataInfo listManage(SeaDevice seaDevice)
    {
        startPage();
        List<SeaDevice> list = seaDeviceService.selectSeaDeviceList(seaDevice);
        return getDataTable(list);
    }

    /**
     * 导出海洋设备列表
     */
    @Log(title = "海洋设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SeaDevice seaDevice)
    {
        List<SeaDevice> list = seaDeviceService.selectSeaDeviceList(seaDevice);
        ExcelUtil<SeaDevice> util = new ExcelUtil<SeaDevice>(SeaDevice.class);
        util.exportExcel(response, list, "海洋设备数据");
    }

    /**
     * 获取海洋设备详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(seaDeviceService.selectSeaDeviceById(id));
    }

    /**
     * 新增海洋设备
     */
    @Log(title = "海洋设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SeaDevice seaDevice)
    {
        LoginUser loginUser = getLoginUser();
        seaDevice.setCreateBy(loginUser.getUser().getUserName());
        return toAjax(seaDeviceService.insertSeaDevice(seaDevice));
    }

    /**
     * 修改海洋设备
     */
    @Log(title = "海洋设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SeaDevice seaDevice)
    {
        return toAjax(seaDeviceService.updateSeaDevice(seaDevice));
    }

    /**
     * 删除海洋设备
     */
    @Log(title = "海洋设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(seaDeviceService.deleteSeaDeviceByIds(ids));
    }
}
